package com.domain.component.mybatis;

import java.util.List;

import com.domain.component.mybatis.sql.Provider;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName: BaseMapper<br>
 * Description: 通用数据基本操作接口.<br>
 * Reason: 通过实体注解的形式组装sql语句 <br>
 * 复杂的sql由继承类自己实现 <br>
 *
 * @param <T>
 * @author Sean
 * @version V1.0
 * @date: 2017年3月7日 下午2:58:34
 * @since JDK 1.8
 */
public interface BaseMapper<T> {

    /**
     * 数据新增
     *
     * @param t
     * @return
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @InsertProvider(method = "insert", type = Provider.class)
    Integer insert(T t) throws Exception;

    /**
     * 数据删除
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @DeleteProvider(method = "delete", type = Provider.class)
    Integer delect(T t) throws Exception;

    /**
     * 数据删除
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @DeleteProvider(method = "deleteBypara", type = Provider.class)
    Integer deleteBypara(T t) throws Exception;

    /**
     * 数据更新
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @UpdateProvider(method = "update", type = Provider.class)
    Integer update(T t) throws Exception;

    /**
     * 外键更新
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @UpdateProvider(method = "updateByForeign", type = Provider.class)
    Integer updateByForeign(T t) throws Exception;

    /**
     * 数据非空禁用更新 <br>
     * DBColumn(update=false)有效
     *
     * @param t
     * @param notNullDisable
     * @return
     * @throws Exception
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    @UpdateProvider(method = "updateNullDisable", type = Provider.class)
    Integer updateNullDisable(T t) throws Exception;

    /**
     * 根据主键查询一条记录
     *
     * @param t
     * @return
     * @throws Exception
     */
    @SelectProvider(method = "queryOne", type = Provider.class)
    T queryOne(T t) throws Exception;

    /**
     * 根据条件查询数据集
     *
     * @param t
     * @return
     * @throws Exception
     */
    @SelectProvider(method = "queryAll", type = Provider.class)
    List<T> queryAll(T t) throws Exception;

    /**
     * 根据like条件查询数据集
     *
     * @param t
     * @return
     * @throws Exception
     */
    @SelectProvider(method = "queryAllLike", type = Provider.class)
    List<T> queryAllLike(T t) throws Exception;

    /**
     * 根据条件获取主键集合
     *
     * @param vehicle
     * @return
     * @throws Exception
     */
    @SelectProvider(method = "queryIdByParam", type = Provider.class)
    List<String> queryIdByParam(T t) throws Exception;

    /**
     * 根据条件获取主键集合
     *
     * @param vehicle
     * @return
     * @throws Exception
     */
    @SelectProvider(method = "queryLimit", type = Provider.class)
    List<T> queryLimit(T t, Integer start, Integer length) throws Exception;
}
